package com.tju.backend.oauth.result;

/**
 * 响应返回工具类
 *
 * @USER: CLS
 */
public class ResultUtil {

    /**
     * 封装返回成功
     *
     * @param unkonwError
     * @return
     */
    public static Result<Object> success(ResultEnum unkonwError) {
        Result<Object> result = new Result<>();
        result.setCode(unkonwError.getCode());
        result.setMsg(unkonwError.getMsg());
        result.setData("");
        return result;
    }

    /**
     * 封装返回自定义数据
     *
     * @param unkonwError
     * @param object
     * @return
     */
    public static Result<Object> success(ResultEnum unkonwError, Object object) {
        Result<Object> result = new Result<>();
        result.setCode(unkonwError.getCode());
        result.setMsg(unkonwError.getMsg());
        result.setData(object);
        return result;
    }

    /**
     * 封装返回自定义数据
     *
     * @param unkonwError
     * @return
     */
    public static Result<Object> success(ResultEnum unkonwError, String msg) {
        Result<Object> result = new Result<>();
        result.setCode(unkonwError.getCode());
        result.setMsg(msg);
        result.setData("");
        return result;
    }

    /**
     * 封装返回自定义数据和数量
     *
     * @param unkonwError
     * @param object
     * @param count
     * @return
     */
    public static Result<Object> success(ResultEnum unkonwError, Object object, long count) {
        Result<Object> result = new Result<>();
        result.setCode(unkonwError.getCode());
        result.setCount(count);
        result.setMsg(unkonwError.getMsg());
        result.setData(object);
        return result;
    }


    /**
     * 封装返回失败
     *
     * @param unkonwError
     * @return
     */
    public static Result<Object> error(ResultEnum unkonwError) {
        Result<Object> result = new Result<Object>();
        result.setCode(unkonwError.getCode());
        result.setMsg(unkonwError.getMsg());
        result.setData("");
        return result;
    }

    /**
     * 封装返回自定义错误信息
     *
     * @param unkonwError
     * @param error
     * @return
     */
    public static Result<Object> error(ResultEnum unkonwError, String error) {
        Result<Object> result = new Result<>();
        result.setCode(unkonwError.getCode());
        result.setMsg(error);
        result.setData("");
        return result;
    }

    /**
     * 封装返回自定义错误信息和数据
     *
     * @param unkonwError
     * @param error
     * @param data
     * @return
     */
    public static Result<Object> error(ResultEnum unkonwError, String error, String data) {
        Result<Object> result = new Result<>();
        result.setCode(unkonwError.getCode());
        result.setMsg(error);
        result.setData(data);
        return result;
    }
}
